﻿
Partial Class RequestServiceTicket
    Inherits System.Web.UI.Page
    Dim cUser As OneCall.User.AuthUser
    Dim SQLDB As New OneCall.DataModel.OneCDataEntities


    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        txtUserName.Focus()

        errorServiceType.Visible = False
        cUser = New OneCall.User.AuthUser(Request, Response)

        If cUser.isActiveSession() Then

            txtUserName.Text = cUser.GetUserFullName()
        Else
            'Response.Redirect("Login.aspx")
            Response.Write("<script>window.open('Login.aspx','_top');</script>")
        End If

    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click


        If serviceType.SelectedValue = "Select" Then
            errorServiceType.Visible = True
            Return
        End If

        Dim isEmailReadyToSend As Boolean = False

        Dim SQLDB As New OneCall.DataModel.OneCDataEntities
        Dim NewRequest As New OneCall.DataModel.Request

        Dim ref As String = ""
        Dim uid = cUser.GetUserID()
        Dim cCustomer = (From p In SQLDB.Customers Where p.Customer_ID = uid Select p).ToArray(0)


        NewRequest.Request_Subject = txtSubject.Text
        NewRequest.Request_Description = txtDescription.Text
        NewRequest.Request_Status = 0
        NewRequest.Request_Date = Now()

       
        Try

            ref = System.Guid.NewGuid.ToString()

            NewRequest.Request_CustomerID = cCustomer.Customer_ID
            NewRequest.Request_FirstName = cCustomer.Customer_FirstName
            NewRequest.Request_LastName = cCustomer.Customer_LastName
            NewRequest.Request_EmailID = cCustomer.Customer_EmailID
            NewRequest.Request_Mobile = cCustomer.Customer_Mobile
            NewRequest.Request_Address = cCustomer.Customer_Address
            NewRequest.Request_City = cCustomer.Customer_City
            NewRequest.Request_State = cCustomer.Customer_State
            NewRequest.Request_Country = cCustomer.Customer_Country
            NewRequest.Request_Pin = cCustomer.Customer_Pin
            NewRequest.Request_ToMessage = cCustomer.Customer_ToMessage
            NewRequest.Request_CustomerActStatus = cCustomer.Customer_AcStatus
            NewRequest.Request_Reference = ref
            NewRequest.Request_Type = serviceType.SelectedValue

            isEmailReadyToSend = True


        Catch ex As Exception

            panelMessage.Visible = False
            panelForm.Visible = False
            panelExist.Visible = True


        End Try

       
        SQLDB.AddToRequests(NewRequest)
        SQLDB.SaveChanges()
        SQLDB.Dispose()


        If isEmailReadyToSend Then

            Dim SQLDBRequest As New OneCall.DataModel.OneCDataEntities
            Dim jstAddedRequest As OneCall.DataModel.Request = (From p In SQLDBRequest.Requests Where p.Request_Reference = ref Select p).ToArray(0)


            Dim msg As String = ""
            msg = msg & "Hi " & cCustomer.Customer_FirstName & "<br>"
            msg = msg & "<br>"
            msg = msg & "Thank you" & "<br>" & "<br>"

            msg = msg & "Your request ID (" & jstAddedRequest.Request_ID & ") is successfully regirstered. one call home care solution executive will reach you soon." & "<br>"

            msg = msg & "" & "<br>"
            msg = msg & "Regards," & "<br>"
            msg = msg & "Customer service" & "<br>"
            msg = msg & "One Call Home Care Solution" & "<br>"
            msg = msg & "www.onecallhomecaresolution.com" & "<br>"
            OneCall.EmailGateway.EMailSender.SendWebEmail(cCustomer.Customer_EmailID, "Your request ID (" & jstAddedRequest.Request_ID & ") is successfully regirstered", msg)

            Dim msgToAdmin As String = ""
            msgToAdmin = msgToAdmin & "Hi Admin" & "<br>"
            msgToAdmin = msgToAdmin & "<br>"
            msgToAdmin = msgToAdmin & cCustomer.Customer_FirstName & " has requested for a service ticket to one call home care. <br>" & "<br>"
            msgToAdmin = msgToAdmin & "" & "<br>"
            msgToAdmin = msgToAdmin & "==============================================" & "<br>"
            msgToAdmin = msgToAdmin & "customer details are  here : " & "<br>"
            msgToAdmin = msgToAdmin & "Date : " & Now() & "<br>"
            msgToAdmin = msgToAdmin & "Service ID (" & jstAddedRequest.Request_ID & ")<br>"
            msgToAdmin = msgToAdmin & "Service Type : " & serviceType.SelectedValue & "<br>"
            msgToAdmin = msgToAdmin & "Service Subject : " & txtSubject.Text & "<br>"
            msgToAdmin = msgToAdmin & "Customer Full Name : " & cCustomer.Customer_FirstName & " " & cCustomer.Customer_LastName & "<br>"
            msgToAdmin = msgToAdmin & "customer Email ID : " & cCustomer.Customer_EmailID & "<br>"
            msgToAdmin = msgToAdmin & "customer Mobile no : " & cCustomer.Customer_Mobile & "<br>"
            msgToAdmin = msgToAdmin & "Description : " & txtDescription.Text & "<br>"
            msgToAdmin = msgToAdmin & "==============================================" & "<br>"
            msgToAdmin = msgToAdmin & "" & "<br>"
            msgToAdmin = msgToAdmin & "Regards," & "<br>"
            msgToAdmin = msgToAdmin & "Customer service" & "<br>"
            msgToAdmin = msgToAdmin & "One Call Home Care Solution" & "<br>"
            msgToAdmin = msgToAdmin & "www.onecallhomecaresolution.com" & "<br>"

            OneCall.EmailGateway.EMailSender.SendWebEmail("info@onecallhomecaresolution.com", "New Request ID (" & jstAddedRequest.Request_ID & ")", msgToAdmin)


            panelMessage.Visible = True
            panelForm.Visible = False

        End If





    End Sub

    Protected Sub serviceType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles serviceType.SelectedIndexChanged

    End Sub
End Class
